/**
 * main js file - copied (approximately) from 
 * http://closure-library.googlecode.com/svn/trunk/closure/goog/demos/editor/helloworld.html
 */
goog.provide('helloworld');

goog.require('goog.editor.Field');
goog.require('goog.editor.Field.EventType');
goog.require('goog.demos.editor.HelloWorld');
goog.require('goog.demos.editor.HelloWorldDialogPlugin');

helloworld.myField = new goog.editor.Field('editMe');

helloworld.setFieldHtml = function() {
    helloworld.myField.setHtml(false, goog.dom.getElement('fieldContents').value);
}

helloworld.doHelloWorld = function() {
    helloworld.myField.execCommand(goog.demos.editor.HelloWorld.COMMAND.HELLO_WORLD);
}

helloworld.doHelloWorldDialog = function() { 
    helloworld.myField.execCommand(
        goog.demos.editor.HelloWorldDialogPlugin.Command.HELLO_WORLD_DIALOG);
}

helloworld.updateFieldContents = function() { 
    goog.dom.getElement('fieldContents').value = helloworld.myField.getCleanContents();
}

// Create and register all of the editing plugins you want to use.
helloworld.myField.registerPlugin(new goog.demos.editor.HelloWorld());
helloworld.myField.registerPlugin(new goog.demos.editor.HelloWorldDialogPlugin());
 
// Watch for field changes, to display below.
goog.events.listen(helloworld.myField, goog.editor.Field.EventType.DELAYEDCHANGE,
    helloworld.updateFieldContents);
 
helloworld.myField.makeEditable();
helloworld.updateFieldContents();
 
// Workaround for bug where on page load hello world doesn't work because
// the field doesn't have focus yet.
helloworld.myField.focusAndPlaceCursorAtStart();

goog.exportSymbol('helloworld.doHelloWorld', helloworld.doHelloWorld);
goog.exportSymbol('helloworld.doHelloWorldDialog', helloworld.doHelloWorldDialog);
goog.exportSymbol('helloworld.setFieldHtml', helloworld.setFieldHtml);
